/** @file ar_proc.h
  *
  * @brief This file contains the proc fs specific defines etc
  *
  *  Copyright (C) 2024, Artosyn Technologies. ALL RIGHTS RESERVED.
  *
  *  This Information is proprietary to Artosyn Technologies and MAY NOT
  *  be copied by any method or incorporated into another program without
  *  the express written consent of Artosyn. This Information or any portion
  *  thereof remains the property of Artosyn. The Information contained herein
  *  is believed to be accurate and Artosyn assumes no responsibility or
  *  liability for its use in any way and conveys no license or title under
  *  any patent or copyright and makes no representation or warranty that this
  *  Information is free from patent or copyright infringement.
  *
  */
#ifndef _AR_PROC_H_
#define _AR_PROC_H_

#include <linux/path.h>
#include <linux/namei.h>
#include <linux/mount.h>
#include <linux/skbuff.h>
#include <linux/poll.h>
#include <linux/kernel.h>
#include <linux/version.h>

typedef void* t_ptr;

/** Length of device name */
#define DEV_NAME_LEN                32

/** Data structure for the Artosyn device */
typedef struct _ar_dev {
    /** device name */
    char name[DEV_NAME_LEN];

    /** echo cmd command */
    uint8_t echo_cmd[256];
    /** debug log level bitmap */
    uint32_t dbg_log_level;
    /** sdio tx TP test mode */
    uint8_t sdio_tx_tp_test;
    /** sdio rx TP test mode */
    uint8_t sdio_rx_tp_test;
    /** sdio tx TP test buf len */
    uint32_t sdio_tx_tp_test_len;
} ar_dev_t, *par_dev_t;

/** Length of prov name */
#define PROC_NAME_LEN                32

/** Item data structure */
struct item_data {
    /** Name */
    char name[PROC_NAME_LEN];
    /** Size */
    uint32_t size;
    /** Address */
    t_ptr addr;
    /** Offset */
    loff_t offset;
    /** Flag */
    uint32_t flag;
    /** Default value */
    uint32_t value;
};

/** Proc private data structure */
struct proc_private_data {
    /** Name */
    char name[PROC_NAME_LEN];
    /** File flag */
    uint32_t fileflag;
    /** Buffer size */
    uint32_t bufsize;
    /** Number of items */
    uint32_t num_items;
    /** Item data */
    struct item_data *pdata;
    /** Private structure */
    void *handle;
    /** File operations */
    const struct file_operations *fops;
};

/** Device proc structure */
struct device_proc {
    /** Proc directory entry */
    struct proc_dir_entry *proc_entry;
    /** num of proc files */
    uint8_t num_proc_files;
    /** pointer to proc_private_data */
    struct proc_private_data *pfiles;
};

/**
 *  @brief This function initializes proc entry
 *
 *  @param handle  A pointer to oal_handle structure
 *  @param name    A pointer to name
 *
 *  @return    0 or -1
 */
int ar_proc_init(void *handle_p, char *name);


/**
 *  @brief This function removes proc interface
 *
 *  @param handle    A pointer to oal_handle structure
 *  @return    N/A
 */
void ar_proc_remove(void *handle_p);


/**
 *  @brief This function creates proc interface
 *  directory structure
 *
 *  @return        0 or -1
 */
int ar_root_proc_init(char* proc_dir_name);

/**
 *  @brief This function removes proc interface
 *  directory structure
 *
 *  @return        0
 */
int ar_root_proc_remove(char* proc_dir_name);

#endif